﻿using _17bangMVC.Models;
using SRV.ServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _17bangMVC.Controllers
{
    public class LogController : Controller
    {

        private IUserService userService;
        public LogController(IUserService userService)
        {
            this.userService = userService;
        }

        // GET: Log
        [HttpGet]
        public ActionResult On()
        {
            return View();
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult On(OnModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            UserModel result = userService.GetByName(model.Name);
            if (result == null)
            {
                ModelState.AddModelError("Name", "用户名不存在");
                return View();
            }
            if (result.Password != model.Password)
            {
                ModelState.AddModelError("Password", "密码错误");
                return View();
            }
            //userId存入cookie
            //int userId = result.Id;

            return View();
        }
    }
}